﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace FindArtInfo.Common
{
    public static class LinkExtensions
    {
        public static MvcHtmlString MyActionLink(
            this HtmlHelper htmlHelper,
            string linkText,
            string action,
            string controller
        )
        {
            var currentAction = htmlHelper.ViewContext.RouteData.GetRequiredString("action");
            var currentController = htmlHelper.ViewContext.RouteData.GetRequiredString("controller");
            if (action == currentAction && controller == currentController)
            {
                var anchor = new TagBuilder("a");
                anchor.Attributes["href"] = "#";
                anchor.AddCssClass("currentPageCSS");
                anchor.SetInnerText(HttpUtility.HtmlDecode(linkText));
                return MvcHtmlString.Create(anchor.ToString());
            }
            return htmlHelper.ActionLink(HttpUtility.HtmlDecode(linkText), action, controller);
        }

        public static MvcHtmlString MyActionLink(
            this HtmlHelper htmlHelper,
            string linkText,
            string action,
            string controller,
            object routeValues, 
            object htmlAttributes
        )
        {
            var currentAction = htmlHelper.ViewContext.RouteData.GetRequiredString("action");
            var currentController = htmlHelper.ViewContext.RouteData.GetRequiredString("controller");
            if (action == currentAction && controller == currentController)
            {
                var anchor = new TagBuilder("a");
                anchor.Attributes["href"] = "#";
                anchor.AddCssClass("currentPageCSS");
                anchor.SetInnerText(HttpUtility.HtmlDecode(linkText));                
                return MvcHtmlString.Create(anchor.ToString());
            }
            return htmlHelper.ActionLink(HttpUtility.HtmlDecode(linkText), action, controller, routeValues, htmlAttributes);
        }
    }
}